package com.luzhikun.servlet3_1;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;


@WebServlet(name = "SomeServlet",
 // 属性urlPatten与属性value功能相同，只能使用一个，不能同时使用，其中value是一个数组，他其中可以存多个值，一个value中可以存在多个url-patten
        value = {"/someServlet","/xxx","/ooo"},
        initParams={@WebInitParam(name="uesername",value = "吴杰"),
                    @WebInitParam(name="password",value = "140489")
                    },
        // 应用启动时创建Servlet实例
        loadOnStartup = 2)

public class servlet3_1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 修改字符集
        response.setContentType("text/html;charset=UTF-8");
        // 获取ServletName
        String servletName = this.getServletName();
        PrintWriter writer = response.getWriter();
        // 获取初始化参数
        Enumeration<String> initParameterNames = this.getInitParameterNames();
        while (initParameterNames.hasMoreElements()){
            String name=initParameterNames.nextElement();
            String initParameter = this.getInitParameter(name);
            writer.write(name+"==="+initParameter);

        }



        writer.write("ServletName"+servletName);


    }


}
